<template>
  <el-dialog @close="qrzjxCancel('qrzjxRuleForm')" :close-on-click-modal="false" title="发起结算单"
    :visible.sync="qrzjxVisible" width="600px" :modal-append-to-body="false">
    <div class="scroll-view">
      <el-form :model="qrzjxRuleForm" :rules="qrzjxRules" ref="qrzjxRuleForm" label-position="top">
        <el-form-item label="备注" prop="remark" style="margin-bottom: 30px">
          <el-input :rows="4" class="input-box" v-model="qrzjxRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button type="primary" @click="qrzjxSubmit('qrzjxRuleForm')" :disabled="diaLoading" :loading="diaLoading">提交</el-button>
      <el-button @click="qrzjxCancel('qrzjxRuleForm')">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
  },
  data() {
    return {
      diaLoading: false,
      qrzjxVisible: false,
      qrzjxRuleForm: {
        remark: "",
      },
      qrzjxRules: {
        remark: [{ required: true, message: "请填写备注", trigger: "change" }],
      },
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.qrzjxVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() { },
  methods: {
    // 确认增减项
    qrzjxCancel(formName) {
      this.qrzjxRuleForm = {
        remark: "",
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    qrzjxSubmit(formName) {
      let qrzjxRuleForm = this.qrzjxRuleForm;
      console.log(qrzjxRuleForm, "确认增减项参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          projectApi
            .confirmIsChangeItem({
              project_id: this.project_id,
              remark: qrzjxRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "确认增减项");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>